
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        .div{
            margin-left: 520px;
            width: 840px;
            height: 500px;
        }
    </style>
    <base href="${pageContext.request.contextPath}/">
    <script src="js/jquery.js"></script>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
</head>
<body>
<br><br><br>
    <div class="div">
        <table border="1">
            <tr>
                <th>类别</th>
                <th>品种</th>
                <th>产地</th>
                <th>总重量（公斤）</th>
                <th>单价（元/公斤）</th>
                <th>操作</th>
            </tr>
        <c:forEach items="${list}" var="fruit">
            <tr>
                <td>${fruit.type}</td>
                <td>${fruit.breed}</td>
                <td>${fruit.area}</td>
                <td>${fruit.weight}</td>
                <td>${fruit.price}</td>
                <td><a href="FruitDetailServlet?id=${fruit.fruitId}">详情</a>&nbsp;
                    <a onclick="deleteUser(${fruit.fruitId})">删除</a></td>
            </tr>
        </c:forEach>

        </table>
    </div>
    <script>
        $(function () {
            //页面刷新
            $.ajax({
                url:"FruitListServlet",
                type:"get"
            })
            //变色效果
            $('tr:first').css("backgroundColor","#535353");
            $('tr:odd').css("backgroundColor","antiquewhite")
            $('tr:even').css("backgroundColor","grey")
        })

        $.get("FruitListServlet");
        function deleteUser(id) {
            var i=confirm("确认要删除吗？");
            if (i) {
                $.get("FruitDelServlet","id="+id,function (data) {
                    if (data==="true") {
                        alert("删除成功");
                        location.href="FruitListServlet"
                    }else {
                        alert("删除失败");
                    }
                });

            }
        }
    </script>
</body>
</html>
